<div class="CNLTreeMenu" id="CNLTreeMenu1">
    <p><a id="AllOpen_1" href="#" onclick="MyCNLTreeMenu1.SetNodes(0);Hd(this);Sw('AllClose_1');">全部展开</a><a id="AllClose_1" href="#" onclick="MyCNLTreeMenu1.SetNodes(1);Hd(this);Sw('AllOpen_1');" style="display: none;">全部折叠</a></p>
    <ul>
        <?php
        $prvLayer = 0;
        foreach ($tree as $key => $value) {
            $id = $value['CatagoryId'];
            $name = $value['Name'];
            $layer = $value['Layer'];
            $isChild = $value['IsChild'];

            if ($prvLayer == 0) {
                echo "<li class='Opened' id='{$id}'>{$name}";
            } else {
                if ($prvLayer < $layer) {
                    echo '<ul>';
                    if ($isChild == "N") {
                        echo "<li class='Closed' id='{$id}'>{$name}";
                    } else {
                        echo "<li class='Child' id='{$id}'>{$name}</li>";
                    }
                } elseif ($prvLayer == $layer) {
                    echo "<li class='Child' id='{$id}'>{$name}</li>";
                } elseif ($prvLayer > $layer) {
                    $i = $layer;
                    while ($i < $prvLayer) {
                        echo "</ul></li>";
                        $i += 1;
                    }
                    if ($isChild == "N") {
                        echo "<li class='Closed' id='{$id}'>{$name}";
                    } else {
                        echo "<li class='Child' id='{$id}'>{$name}</li>";
                    }
                }
            }
            $prvLayer = $layer;
        }
        $i = $layer;
        while ($i > 1) {
            echo "</ul></li>";
            $i -= 1;
        }
        ?>
    </ul>
</div>
<script type="text/javascript">
<!--
var MyCNLTreeMenu1=new CNLTreeMenu("CNLTreeMenu1","li");
MyCNLTreeMenu1.InitCss("Opened","Closed","Child","<?php echo base_url(); ?>style/s.gif");
-->
</script>